<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>websocket</title>
  <script src="https://cdn.bootcdn.net/ajax/libs/socket.io/4.1.3/socket.io.min.js"></script>
</head>

<body>

  <script>
    var socket = io('ws://localhost:3003/', {
      extraHeaders: {
        Authorization: "Bearer authorization_token_here"
      }
    });

    socket.on('news', function (data) {
      console.log(data);
      socket.emit('event', { name: '事件' });
      socket.emit('otherEvent', { name: '自定义事件' });
    });
  </script>
</body>

</html>